package cn.bbs.ba.Timer;


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;

import cn.bbs.ba.log.LogTrac;

public class ContextListener extends HttpServlet implements
		ServletContextListener {
	public ContextListener() {
	}

	private java.util.Timer timer = null;
	private java.util.Timer timer2 = null;

	public void contextInitialized(ServletContextEvent event) {
		timer = new java.util.Timer(true);
		timer2 = new java.util.Timer(true);
		event.getServletContext().log("contextInitialized start");
		try {
			//timer.schedule(new MyTask(event.getServletContext()), 0, 60*1000);
			// 3min 
			timer.schedule(new Timer4Index(event.getServletContext()), 0, 3*60*1000);
			// 每秒刷新
			timer2.schedule(new MiaoAction(event.getServletContext()), 0, 1000);
			event.getServletContext().log("contextInitialized end");
		} catch (Exception e) {
			LogTrac.error("contextInitialized error");
		}
	}

	public void contextDestroyed(ServletContextEvent event) {
		timer.cancel();
		event.getServletContext().log("contextInitialized contextDestroyed");
	}

}
